#[cfg(test)]
mod tests {

    #[test]
    fn test_unsafe_seq() {
        super::start();
    }
}

use std::thread;
use std::time::Duration;

static mut V: i32 = 0;

fn unsafe_seq() -> i32 {
    unsafe {
        V += 1;
        V
    }
}

/// 在多线程环境中使用 unsafe seq 函数
pub fn start() {
    let child = thread::spawn(|| {
        for _ in 0..10 {
            unsafe_seq();
            unsafe { println!("child : {}", V) }
        }
    });
    let child_two = thread::spawn(|| {
        for _ in 0..10 {
            unsafe_seq();
            unsafe { println!("child two: {}", V) }
        }
    });
    thread::sleep(Duration::from_nanos(10));
    for _ in 0..10 {
        unsafe_seq();
        unsafe { println!("main : {}", V) }
    }
    child_two.join().unwrap();
    child.join().unwrap();
}
